//
//  HomeCardLineChartView.swift
//  MoyoungHome
//
//  Created by 易先生 on 2022/9/26.
//

import UIKit
import SnapKit

open class HomeCardLineChartView: View {

    var lineColor:UIColor = .gray
    var gradientColors:[UIColor] = [.white,.white]
    var lineWidth:Double = 2

    
    open override func makeUI() {
        self.backgroundColor = .clear
        self.addSubview(lineChartView)
        lineChartView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    func bind(by viewModel:HomeCardChatViewModel){
        
        self.lineChartView.setBarCount(viewModel.getBarCount())
        self.lineChartView.setXAxis(valueFormatter: viewModel.getXAxisValueFotmatter())
        self.lineChartView.setYMax(value: viewModel.getBarMaxValue())
        self.lineChartView.setData(viewModel.dataSource.map{max($0, viewModel.getBarMinValue())},
                                   lineColor: self.lineColor,
                                   gradientColors: self.gradientColors,
                                   lineWidth: self.lineWidth)
    }
    
    public func setChartConfig(_ config:DFLineChartViewConfig){
        self.lineChartView.setConfig(config)
    }
    
    private lazy var lineChartView: DFLineChartView = {
        let view = DFLineChartView.init(frame:.zero)
        return view
    }()

}
